<?php

namespace app\common\model\dormitory;

use think\Model;

class DormitoryFloorRoom extends Model 
{ 
    protected $name = 'dormitory_floor_room'; 

    protected $schema = [
        'id'             => 'int', //房间表
        'room_name'             => 'varchar', //名称
        'status'             => 'tinyint', //-1 删除 0默认 1正常
        'update_time'             => 'datetime', //更新时间
        'remark'             => 'varchar', //备注
        'create_time'             => 'datetime', //创建时间
        'admin_name'             => 'varchar', //操作者
        'floor_id'             => 'int', //所属楼层
        'room_type'             => 'tinyint', //[select] 【1-管理房|2-员工房|3-夫妻房
        'number'             => 'int', //可入住人数
        'already_number'             => 'int', //已入住人数
        'already_person_str'             => 'varchar', //已入住人员
    ];

    //处理数据模型 
    public static function fillModels($models){ 
        $list = []; 
        foreach ($models as $model) { 
            $listItem = static::fillModel($model); 
            $list[] = $listItem; 
        } 
        return $list; 
    } 

    public static function fillModel($model){ 
        $data = [];
        $data['id'] = $model['id'];
        $data['room_name'] = $model['room_name'];
        $data['status'] = (string)$model['status'];
        $data['update_time'] = $model['update_time'];
        $data['remark'] = $model['remark'];
        $data['create_time'] = $model['create_time'];
        $data['admin_name'] = $model['admin_name'];
        $data['floor_id'] = $model['floor_id'];
        $data['room_type'] = (string)$model['room_type'];
        $data['room_type_name'] = self::getRoomTypeName($model['room_type']);
        $data['number'] = $model['number'];
        $data['already_number'] = $model['already_number'];
        $data['already_person_str'] = $model['already_person_str'];
        return $data;
    } 

    /** 
     *【方法注释】处理[select] 【1-管理房|2-员工房|3-夫妻房
     *@param $value 传入的值
     *@param string 返回的值
     */
    public static function getRoomTypeName($value){
    } 

    /** 
     *【方法注释】获取数据列表 
     *@param $where 查询的条件数组
     *@param $limit_start 获取数据，从第$limit_start条数据开始
     *@param $page_size 获取数据，从第$limit_start条数据开始，取$page_size条数据
     *@param array 返回的数据，数组
     */
    public static function getList($where, $limit_start, $page_size){
        $lists =  self::where($where)->order('id','desc')->limit($limit_start,$page_size)->select();
        return self::fillModels($lists);
    } 

    /** 
     *【方法注释】获取数据条数 
     *@param $where 查询的条件数组
     *@param int 返回的数据条数
     */
    public static function getCount($where){
        return self::where($where)->count();
    } 

    /** 
     *【方法注释】获取单条数据 
     *@param $where 查询的条件数组
     *@param array 返回的单条数据
     */
    public static function getOne($where){
        return self::fillModel(self::where($where)->find());
    } 

} 
